namespace LetLord.Migrations
{
    using System;
    using System.Data.Entity.Migrations;
    
    public partial class initial : DbMigration
    {
        public override void Up()
        {
            CreateTable(
                "dbo.UserProfile",
                c => new
                    {
                        UserId = c.Int(nullable: false, identity: true),
                        UserName = c.String(nullable: false),
                        FirstName = c.String(nullable: false),
                        LastName = c.String(nullable: false),
                        Email = c.String(nullable: false),
                        AccountTypeString = c.String(),
                    })
                .PrimaryKey(t => t.UserId);
            
            CreateTable(
                "dbo.ResidentialProperty",
                c => new
                    {
                        ResidentialPropertyId = c.Int(nullable: false, identity: true),
                        SizeSquareMeters = c.String(),
                        NumberOfBedrooms = c.String(),
                        NumberOfBathrooms = c.String(),
                        NumberOfReceptionRooms = c.String(),
                        Description = c.String(),
                        HasBackGarden = c.Boolean(nullable: false),
                        HasFrontGarden = c.Boolean(nullable: false),
                        IsDisabledFriendly = c.Boolean(nullable: false),
                        HasSecureParking = c.Boolean(nullable: false),
                        DateAdded = c.DateTime(nullable: false),
                        PropertyTypeString = c.String(),
                        UserId = c.Int(nullable: false),
                        AddressId = c.Int(nullable: false),
                        Discriminator = c.String(nullable: false, maxLength: 128),
                        Tenant_UserId = c.Int(),
                    })
                .PrimaryKey(t => t.ResidentialPropertyId)
                .ForeignKey("dbo.Tenant", t => t.Tenant_UserId)
                .ForeignKey("dbo.Landlord", t => t.UserId, cascadeDelete: true)
                .ForeignKey("dbo.Address", t => t.AddressId, cascadeDelete: true)
                .Index(t => t.Tenant_UserId)
                .Index(t => t.UserId)
                .Index(t => t.AddressId);
            
            CreateTable(
                "dbo.Image",
                c => new
                    {
                        ImageId = c.Int(nullable: false, identity: true),
                        Format = c.String(),
                        Name = c.String(),
                        Description = c.String(),
                        File = c.Binary(),
                        DateUploaded = c.DateTime(nullable: false),
                    })
                .PrimaryKey(t => t.ImageId);
            
            CreateTable(
                "dbo.Viewing",
                c => new
                    {
                        ViewingId = c.Int(nullable: false, identity: true),
                        ViewingDate = c.DateTime(nullable: false),
                        StartTime = c.DateTime(nullable: false),
                        EndTime = c.DateTime(nullable: false),
                        ResidentialPropertyId = c.Int(nullable: false),
                        UserId = c.Int(nullable: false),
                    })
                .PrimaryKey(t => t.ViewingId)
                .ForeignKey("dbo.ResidentialProperty", t => t.ResidentialPropertyId, cascadeDelete: false)
                .ForeignKey("dbo.Landlord", t => t.UserId, cascadeDelete: true)
                .Index(t => t.ResidentialPropertyId)
                .Index(t => t.UserId);
            
            CreateTable(
                "dbo.TenantGroupMember",
                c => new
                    {
                        TenantGroupMemberId = c.Int(nullable: false, identity: true),
                        TenantGroupMemberName = c.String(),
                        TenantGroupMemberAge = c.String(),
                        UserId = c.Int(nullable: false),
                    })
                .PrimaryKey(t => t.TenantGroupMemberId)
                .ForeignKey("dbo.Tenant", t => t.UserId, cascadeDelete: true)
                .Index(t => t.UserId);
            
            CreateTable(
                "dbo.Address",
                c => new
                    {
                        AddressId = c.Int(nullable: false, identity: true),
                        Latitude = c.String(),
                        Longitude = c.String(),
                        Line1 = c.String(),
                        Line2 = c.String(),
                        TownCity = c.String(),
                        County = c.String(),
                        PostCode = c.String(),
                    })
                .PrimaryKey(t => t.AddressId);
            
            CreateTable(
                "dbo.TenantPreferences",
                c => new
                    {
                        TenantPreferencesId = c.Int(nullable: false, identity: true),
                        Name = c.String(),
                        Weighting = c.Int(nullable: false),
                        IsSelected = c.Boolean(nullable: false),
                        UserId = c.Int(nullable: false),
                    })
                .PrimaryKey(t => t.TenantPreferencesId)
                .ForeignKey("dbo.Tenant", t => t.UserId, cascadeDelete: true)
                .Index(t => t.UserId);
            
            CreateTable(
                "dbo.LandlordPreferences",
                c => new
                    {
                        LandLordPreferencesId = c.Int(nullable: false, identity: true),
                        Name = c.String(),
                        Weighting = c.Int(nullable: false),
                        IsSelected = c.Boolean(nullable: false),
                        UserId = c.Int(nullable: false),
                    })
                .PrimaryKey(t => t.LandLordPreferencesId)
                .ForeignKey("dbo.Landlord", t => t.UserId, cascadeDelete: true)
                .Index(t => t.UserId);
            
            CreateTable(
                "dbo.TenantViewing",
                c => new
                    {
                        Tenant_UserId = c.Int(nullable: false),
                        Viewing_ViewingId = c.Int(nullable: false),
                    })
                .PrimaryKey(t => new { t.Tenant_UserId, t.Viewing_ViewingId })
                .ForeignKey("dbo.Tenant", t => t.Tenant_UserId)
                .ForeignKey("dbo.Viewing", t => t.Viewing_ViewingId)
                .Index(t => t.Tenant_UserId)
                .Index(t => t.Viewing_ViewingId);
            
            CreateTable(
                "dbo.Landlord",
                c => new
                    {
                        UserId = c.Int(nullable: false),
                    })
                .PrimaryKey(t => t.UserId)
                .ForeignKey("dbo.UserProfile", t => t.UserId)
                .Index(t => t.UserId);
            
            CreateTable(
                "dbo.PropertyPhoto",
                c => new
                    {
                        ImageId = c.Int(nullable: false),
                        ResidentialPropertyId = c.Int(nullable: false),
                    })
                .PrimaryKey(t => t.ImageId)
                .ForeignKey("dbo.Image", t => t.ImageId)
                .ForeignKey("dbo.ResidentialProperty", t => t.ResidentialPropertyId, cascadeDelete: true)
                .Index(t => t.ImageId)
                .Index(t => t.ResidentialPropertyId);
            
            CreateTable(
                "dbo.Tenant",
                c => new
                    {
                        UserId = c.Int(nullable: false),
                        TenantAge = c.String(maxLength: 3),
                        PersonalDescription = c.String(maxLength: 500),
                        MinBudget = c.Decimal(nullable: false, precision: 18, scale: 2),
                        MaxBudget = c.Decimal(nullable: false, precision: 18, scale: 2),
                        IsProfessional = c.Boolean(nullable: false),
                        IsStudent = c.Boolean(nullable: false),
                        HasChildren = c.Boolean(nullable: false),
                        HasRentAllowance = c.Boolean(nullable: false),
                        IsInGroup = c.Boolean(nullable: false),
                        DateWantToRentFrom = c.DateTime(nullable: false),
                        DateWantToRentTo = c.DateTime(nullable: false),
                        DesiredPropertyLocation = c.String(),
                        DesiredNumberOfBedroomsString = c.String(),
                    })
                .PrimaryKey(t => t.UserId)
                .ForeignKey("dbo.UserProfile", t => t.UserId)
                .Index(t => t.UserId);
            
            CreateTable(
                "dbo.ReferencePhoto",
                c => new
                    {
                        ImageId = c.Int(nullable: false),
                        UserId = c.Int(nullable: false),
                    })
                .PrimaryKey(t => t.ImageId)
                .ForeignKey("dbo.Image", t => t.ImageId)
                .ForeignKey("dbo.Tenant", t => t.UserId, cascadeDelete: true)
                .Index(t => t.ImageId)
                .Index(t => t.UserId);
            
        }
        
        public override void Down()
        {
            DropIndex("dbo.ReferencePhoto", new[] { "UserId" });
            DropIndex("dbo.ReferencePhoto", new[] { "ImageId" });
            DropIndex("dbo.Tenant", new[] { "UserId" });
            DropIndex("dbo.PropertyPhoto", new[] { "ResidentialPropertyId" });
            DropIndex("dbo.PropertyPhoto", new[] { "ImageId" });
            DropIndex("dbo.Landlord", new[] { "UserId" });
            DropIndex("dbo.TenantViewing", new[] { "Viewing_ViewingId" });
            DropIndex("dbo.TenantViewing", new[] { "Tenant_UserId" });
            DropIndex("dbo.LandlordPreferences", new[] { "UserId" });
            DropIndex("dbo.TenantPreferences", new[] { "UserId" });
            DropIndex("dbo.TenantGroupMember", new[] { "UserId" });
            DropIndex("dbo.Viewing", new[] { "UserId" });
            DropIndex("dbo.Viewing", new[] { "ResidentialPropertyId" });
            DropIndex("dbo.ResidentialProperty", new[] { "AddressId" });
            DropIndex("dbo.ResidentialProperty", new[] { "UserId" });
            DropIndex("dbo.ResidentialProperty", new[] { "Tenant_UserId" });
            DropForeignKey("dbo.ReferencePhoto", "UserId", "dbo.Tenant");
            DropForeignKey("dbo.ReferencePhoto", "ImageId", "dbo.Image");
            DropForeignKey("dbo.Tenant", "UserId", "dbo.UserProfile");
            DropForeignKey("dbo.PropertyPhoto", "ResidentialPropertyId", "dbo.ResidentialProperty");
            DropForeignKey("dbo.PropertyPhoto", "ImageId", "dbo.Image");
            DropForeignKey("dbo.Landlord", "UserId", "dbo.UserProfile");
            DropForeignKey("dbo.TenantViewing", "Viewing_ViewingId", "dbo.Viewing");
            DropForeignKey("dbo.TenantViewing", "Tenant_UserId", "dbo.Tenant");
            DropForeignKey("dbo.LandlordPreferences", "UserId", "dbo.Landlord");
            DropForeignKey("dbo.TenantPreferences", "UserId", "dbo.Tenant");
            DropForeignKey("dbo.TenantGroupMember", "UserId", "dbo.Tenant");
            DropForeignKey("dbo.Viewing", "UserId", "dbo.Landlord");
            DropForeignKey("dbo.Viewing", "ResidentialPropertyId", "dbo.ResidentialProperty");
            DropForeignKey("dbo.ResidentialProperty", "AddressId", "dbo.Address");
            DropForeignKey("dbo.ResidentialProperty", "UserId", "dbo.Landlord");
            DropForeignKey("dbo.ResidentialProperty", "Tenant_UserId", "dbo.Tenant");
            DropTable("dbo.ReferencePhoto");
            DropTable("dbo.Tenant");
            DropTable("dbo.PropertyPhoto");
            DropTable("dbo.Landlord");
            DropTable("dbo.TenantViewing");
            DropTable("dbo.LandlordPreferences");
            DropTable("dbo.TenantPreferences");
            DropTable("dbo.Address");
            DropTable("dbo.TenantGroupMember");
            DropTable("dbo.Viewing");
            DropTable("dbo.Image");
            DropTable("dbo.ResidentialProperty");
            DropTable("dbo.UserProfile");
        }
    }
}
